package com.kundi.dooradmin.controller;

import com.kundi.dooradmin.entity.SuccessExample;
import com.kundi.dooradmin.service.SuccessExampleService;
import com.kundi.dooradmin.util.MapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Author 赵恒
 * Date 2020/6/19
 */
@Controller
@RequestMapping("/successExample")
public class SuccessExampleController {
    @Resource
    SuccessExampleService successExampleService;
    @RequestMapping("/getAll")
    @ResponseBody
    public List<SuccessExample> getAll() {
        return successExampleService.getAll();
    }
    @RequestMapping("insert")
    @ResponseBody
    public Map<String, String> insert(SuccessExample successExample) {
        System.out.println(successExample);
        int i = successExampleService.insert(successExample);
        if(i > 0) {
            return MapUtil.responseMap("添加成功", "success");
        } else {
            return MapUtil.responseMap("添加失败", "false");
        }
    }
    @RequestMapping("update")
    @ResponseBody
    public Map<String, String> update(SuccessExample successExample) {
        int i = successExampleService.update(successExample);
        if(i > 0) {
            return MapUtil.responseMap("修改成功", "success");
        } else {
            return MapUtil.responseMap("修改失败", "false");
        }
    }
    @RequestMapping("delete")
    @ResponseBody
    public Map<String, String> delete(Integer id) {
        int i = successExampleService.delete(id);
        if(i > 0) {
            return MapUtil.responseMap("删除成功", "success");
        } else {
            return MapUtil.responseMap("删除失败", "false");
        }
    }
    @RequestMapping("/getExampleById")
    @ResponseBody
    public SuccessExample getExampleById(Integer id) {
        return successExampleService.getExampleById(id);
    }
}
